package com.zkjl.protect_business.controller;

import com.zkjl.protect_business.common.ApiResponse;
import com.zkjl.protect_business.dto.AssessmentPoliticalDTO;
import com.zkjl.protect_business.dto.PageBaseDTO;
import com.zkjl.protect_business.dto.SortDTO;
import com.zkjl.protect_business.entity.AssessmentPolitical;
import com.zkjl.protect_business.service.AssessmentPoliticalService;
import com.zkjl.protect_business.utils.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageImpl;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@Api(tags = {"政治考核"})
public class AssessmentPoliticalController {

    @Autowired
    AssessmentPoliticalService assessmentPoliticalService;

    @ApiOperation(value = "创建政治考核", notes = "创建政治考核", httpMethod = "POST")
    @PostMapping(value = "business/{businessId}/assessmentPoliticals")
    ApiResponse<AssessmentPolitical> save(@RequestBody @Valid AssessmentPoliticalDTO assessmentPoliticalDTO, @PathVariable String businessId) {

        AssessmentPolitical assessmentPolitical = assessmentPoliticalService.save(assessmentPoliticalDTO, businessId);
        return ApiResponse.ofSuccess(assessmentPolitical);
    }

    @ApiOperation(value = "获取政治考核列表", notes = "获取政治考核列表", httpMethod = "GET")
    @GetMapping(value = "assessmentPoliticals")
    ApiResponse<PageImpl<AssessmentPolitical> > page(PageBaseDTO pageBaseDTO, SortDTO sortDTO, String org, Long assessmentTime) {

        PageImpl<AssessmentPolitical> page = assessmentPoliticalService.page(pageBaseDTO, sortDTO, org, assessmentTime);
        return ResultUtil.successPagesVO(page);
    }

    @ApiOperation(value = "删除政治考核", notes = "删除政治考核", httpMethod = "DELETE")
    @DeleteMapping(value = "assessmentPoliticals/{id}")
    ApiResponse del(@PathVariable String id) {

        Boolean del = assessmentPoliticalService.del(id);
        return ApiResponse.ofSuccess(del);
    }

}
